package main

import "fmt"

func feb(n int) []uint64 {
	fbnSlice := make([]uint64, n)
	fbnSlice[0] = 1
	fbnSlice[1] = 1
	for i := 2; i < n; i++ {
		fbnSlice[i] = fbnSlice[i-1] + fbnSlice[i-2]
	}
	return fbnSlice
}

func main() {
	//切片的基本使用
	var intArr [5]int = [...]int{1, 2, 33, 44, 55}
	slice := intArr[1:3] //slice引用intArr这个数组含头不含尾
	fmt.Println(intArr)
	fmt.Println(slice)
	fmt.Println("slice的元素个数=", len(slice))
	fmt.Println("slice的容量=", cap(slice))
	var sl []int64 = make([]int64, 5, 10)
	sl[1] = 10
	sl[3] = 20
	fmt.Println(sl)
	var s []int = []int{1, 2, 3, 4}
	var ss []string = []string{"tom", "jack", "mary"}
	fmt.Println(s, ss)
	for i := 0; i < len(s); i++ {
		fmt.Printf("s[%d]=%v\n", i, s[i])
	}
	for index, val := range s {
		fmt.Printf("s[%d]=%v\n", index, val)
	}

	s1 := s[1:3]
	s1[0] = 100 //切片的切片改变会影响之前的切片
	fmt.Println(s1, s)
	//append动态追加
	var slice3 []int = []int{100, 200, 300}
	slice3 = append(slice3, 400, 500, 600)
	slice3 = append(slice3, slice3...)
	//copy拷贝操作
	var slice4 []int = []int{1, 2, 3, 4, 5, 6, 7}
	var slice5 = make([]int, 10)
	copy(slice5, slice4)
	fmt.Println("slice5", slice5)
	str := "hello Summer"
	slice6 := str[6:]
	fmt.Println(slice6)
	//arr1 := []byte(str)
	//arr1[0] = 'z'
	//str = string(arr1)
	//fmt.Println(str)
	arr1 := []rune(str)
	arr1[0] = '夏'
	str = string(arr1)
	fmt.Println(str)
	//练习
	fnbSlice := feb(100)
	fmt.Println(fnbSlice)

}
